<?php
session_start();
	include('../controller/functions.php');
	require_once '../controller/validation.php';
	User::connection();

$userArr	= array('admin');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
		print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';
}


?>


<script type="text/javascript" src="../javascripts/jquery.js"></script>
	<script type="text/javascript" src="../javascripts/validation.js"></script>
    <script type="text/javascript" src="../javascripts/jquery-ui-1.7.2.custom.min.js"> </script>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>Add Replace | Add New Word</title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
 	<link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/jquery-ui-1.7.2.custom.css" type="text/css" charset="utf-8" />
      <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
</head>
<body>
 <div id="page">
<div id="wrapper">      	
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- nav-->    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
      <p> </p>
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
        <div id="chef_ind"> <!--open chef --><!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>

        </div>
        
      </div><!--close left -->
      
    <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3"><h1>Add Words </h1> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg"><!--open booking -->
		<?if( isset($_POST['send']) && (!validateRep($_POST['repName'])|| !validateOrig($_POST['repName'])) ):?>
				<div id="error">
					<ul>
						<?if(!validateRep($_POST['repName'])):?>
							<li><strong>Invalid:</strong> We want more than 3 letters!</li>
						<?endif?>
                       <?if(!validateOrig($_POST['origName'])):?>
							<li><strong>Invalid:</strong> We want more than 3 letters!</li>
						<?endif?>
                    
					</ul>
				</div>
		
		<!--Replace Words -->
				
				<? elseif(isset($_POST['send'])):
				
				$password = mt_rand() . mt_rand() . mt_rand();
			
            		$query = "INSERT INTO `tblreplace`(`replaceWord`,`origWord`,`creatorName`,`date`) VALUES('$_POST[repName]','$_POST[origName]','none',NOW())";
	$res = @mysql_query($query);
		
	
	
	if($res){
		
		echo '<div id="okay"><br />Done!<br /></div>';
		echo '<div>
		
		This word '.$_POST['origName'].' Will be replace by: '.$_POST['repName'].'<br />
		

		<br />
		
		 <a href="createReplace.php"><input id="bbtn" type="button" value="Add Words" name="Add Words"/> </a>
		 
	</div>
  </div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
		
		  
		';
			
		 echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';
	}
	else{
		echo '<div id="error">Error occured while saving!</div>';
	}  
	
	if(!$res)
		die("Error: ".mysql_error());
	else
		return $res;
			
            ?>
            
            <div id="error" class="valid">
					<ul>
						<li><strong>Congratulations!</strong> All fields are OK ;)</li>
					</ul>
				</div>	
		<?endif?>

		<form method="post" id="addReplace" action="">
			<div>
				<label for="origName">Original Word</label>
				<input id="origName" name="origName" type="text" />
				<span id="origNameInfo">Original Name</span>
			</div>
            <div>
				<label for="repName">Replace Word</label>
				<input id="repName" name="repName" type="text" />
				<span id="repNameInfo">Replace Name</span>
			</div>
      		
			<div>
				<input id="send" name="send" type="submit" value="Send" />
			</div>
		</form>
	</div><!--close desc -->
   
        
         </div> <!--close container-->
   			
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>



